*********************************
* IRCA and Redistricting
* Navid Sabet and Noam Yuchtman
* Figure 9: IRCA and county political outcomes
*******************************

	//Load data
	use irca_gerrymander.dta, clear
		
	//Controls
	global controls  c.pop1990#i.p102_full c.inc_pc1990#i.p102_full  c.age_share1990#i.p102_full c.unemployment_1990#i.p102_full c.educ1990##i.p102_full c.births_1990#i.p102_full c.black_share1990#i.p102_full c.white_share1990#i.p102_full
	
	//Fully interacted controls
	global controls_full  c.pop1990##i.p102_full##i.legal_control_kaplan1991 c.inc_pc1990##i.p102_full##i.legal_control_kaplan1991  c.age_share1990##i.p102_full##i.legal_control_kaplan1991 c.unemployment_1990##i.p102_full##i.legal_control_kaplan1991 c.educ1990##i.p102_full##i.legal_control_kaplan1991 c.births_1990##i.p102_full##i.legal_control_kaplan1991 c.black_share1990##i.p102_full##i.legal_control_kaplan1991 c.white_share1990##i.p102_full##i.legal_control_kaplan1991
	
	//VRA Controls
	global vra_control i.vra_covered##i.p102_full
	global vra_full i.vra_covered##i.p102_full##i.legal_control_kaplan1991 
	
	//Extra controls
	global extras c.povrate_1990#i.p102_full c.hsd_share1990#i.p102_full c.spr010_1990#i.p102_full c.spr030_1990#i.p102_full c.housing_value_1990#i.p102_full c.crime_1990#1.p102_full
	
	 //1980 Controls
	global controls1980 c.population_bea1980#i.p102_full c.income_pc1980#i.p102_full  c.age_share1980#i.p102_full c.edu6351980#i.p102_full c.births_1980#i.p102_full c.black_share1980#i.p102_full c.white_share1980#i.p102_full
	
	//Controls pre post 1980 redistricting (placebo model controls)
	global controls97 c.pop1990#i.p97_full c.inc_pc1990#i.p97_full  c.age_share1990#i.p97_full c.unemployment_1990#i.p97_full c.educ1990##i.p97_full c.births_1990#i.p97_full c.black_share1990#i.p97_full c.white_share1990#i.p97_full
		
	//VRA controls: pre post 1980 redistricting (placebo model controls)
	global vra_control97 i.vra_covered##i.p97_full
	
	//Fixed effects
	global fe id congress#StateFIPS c.hisp_share1980#i.congress i.unassigned_county#i.congress 
	
	//Clustering
	global cluster id

	//Generate filler variables.
	gen x_base = legal_control_kaplan1991
	gen x_none = legal_control_kaplan1991
	gen x_extra = legal_control_kaplan1991
	gen x_1980 = legal_control_kaplan1991
	gen x_full = legal_control_kaplan1991
	gen x_arp = arp_nocommission
	gen x_hisp = legal_control_kaplan1991
	gen x_treated = legal_control_kaplan1991
	gen x_single = legal_control_kaplan1991
	gen x_mm = legal_control_kaplan1991
	gen x_placebo = legal_control_kaplan1981
	
****************
* Hispanic Wins the Seat
****************
eststo clear
	 //Baseline
	reghdfe hisp_representative_county $controls $vra_control c.irca_std##1.p102_full##ib2.x_base [weight = cuts] , a($fe) cluster($cluster)
	estadd scalar clusters = e(N_clust)
	eststo base
	sum hisp_representative_county if e(sample) & p102_full==0
	
	 //No controls
	reghdfe hisp_representative_county c.irca_std##i.p102_full##ib2.x_none [weight = cuts] , a($fe) cluster($cluster)
	estadd scalar clusters = e(N_clust)
	eststo none
	
	//Extra controls
	reghdfe hisp_representative_county $controls $vra_control $extras c.irca_std##i.p102_full##ib2.x_extra [weight = cuts] , a($fe) cluster($cluster)
	estadd scalar clusters = e(N_clust)
	eststo extra
	
	//1980 Controls
	reghdfe hisp_representative_county $controls1980 $vra_control c.irca_std##i.p102_full##ib2.x_1980 [weight = cuts] , a($fe) cluster($cluster)	
	estadd scalar clusters = e(N_clust)
	eststo 	eighty
	
	//Interacted Observables (Fully Saturated)
	reghdfe hisp_representative_county $controls_full $vra_full c.irca_std##i.p102_full##ib2.legal_control_kaplan1991 [weight = cuts] , a($fe) cluster($cluster)
	estadd scalar clusters = e(N_clust)
	eststo full
	
	//Alternative Definition of Legal Control
	reghdfe hisp_representative_county $controls $vra_control c.irca_std##i.p102_full##ib2.x_arp [weight = cuts] , a($fe) cluster($cluster)
	estadd scalar clusters = e(N_clust)
	eststo arp
	
	//Using Hispanic share instead of imputing
	reghdfe hisp_representative_county $controls $vra_control c.irca_pc1990_hisp_std##i.p102_full##ib2.x_hisp [weight = cuts] , a($fe) cluster($cluster)
	estadd scalar clusters = e(N_clust)
	eststo hisp
	
	//Drop imputed counties
	reghdfe hisp_representative_county $controls $vra_control c.irca_std##i.p102_full##ib2.x_treated if unassigned_county == 0 [weight = cuts], a($fe) cluster($cluster)
	estadd scalar clusters = e(N_clust)
	eststo no_impute
	
	 //Only single district counties
	reghdfe hisp_representative_county $controls $vra_control c.irca_std##1.p102_full##ib2.x_single [weight = cuts] if cuts==1, a($fe) cluster($cluster)
	estadd scalar clusters = e(N_clust)
	eststo single_dist
	
	//Drop minority-majority counties
	reghdfe hisp_representative_county $controls $vra_control c.irca_std##1.p102_full##ib2.x_mm [weight = cuts] if StateFIPS!=35, a($fe) cluster($cluster)
	estadd scalar clusters = e(N_clust)
	eststo mm
	
	//Falsification
	reghdfe hisp_representative_county $controls97 $vra_control97 c.irca_std##i.p97_full##ib2.x_placebo [weight = cuts] , a($fe) cluster($cluster)
	estadd scalar clusters = e(N_clust)
	eststo placebo
	 
	
****************
* Dem Vote Share Congressional Elections
****************		
	//Baseline
	reghdfe d_share_county $controls $vra_control c.irca_std##1.p102_full##ib2.x_base [weight = cuts] , a($fe) cluster($cluster)
	estadd scalar clusters = e(N_clust)
	eststo base_dem
	sum d_share_county if e(sample) & p102_full==0
	
	 //No controls
	reghdfe d_share_county c.irca_std##i.p102_full##ib2.x_none [weight = cuts] , a($fe) cluster($cluster)
	estadd scalar clusters = e(N_clust)
	eststo none_dem
	
	//Extra controls
	reghdfe d_share_county $controls $vra_control $extras c.irca_std##i.p102_full##ib2.x_extra [weight = cuts] , a($fe) cluster($cluster)
	estadd scalar clusters = e(N_clust)
	eststo extra_dem
	
	//1980 Controls
	reghdfe d_share_county $controls1980 $vra_control c.irca_std##i.p102_full##ib2.x_1980 [weight = cuts] , a($fe) cluster($cluster)	
	estadd scalar clusters = e(N_clust)
	eststo 	eighty_dem
	
	//Interacted Observables (Fully Saturated)
	reghdfe d_share_county $controls_full $vra_full c.irca_std##i.p102_full##ib2.legal_control_kaplan1991 [weight = cuts] , a($fe) cluster($cluster)
	estadd scalar clusters = e(N_clust)
	eststo full_dem
	
	//Alternative Definition of Legal Control
	reghdfe d_share_county $controls $vra_control c.irca_std##i.p102_full##ib2.x_arp [weight = cuts] , a($fe) cluster($cluster)
	estadd scalar clusters = e(N_clust)
	eststo arp_dem
	
	//Using Hispanic share instead of imputing
	reghdfe d_share_county $controls $vra_control c.irca_pc1990_hisp_std##i.p102_full##ib2.x_hisp [weight = cuts] , a($fe) cluster($cluster)
	estadd scalar clusters = e(N_clust)
	eststo hisp_dem
	
	//Drop imputed counties
	reghdfe d_share_county $controls $vra_control c.irca_std##i.p102_full##ib2.x_treated if unassigned_county == 0 [weight = cuts], a($fe) cluster($cluster)
	estadd scalar clusters = e(N_clust)
	eststo no_impute_dem
	
	 //Only single district counties
	reghdfe d_share_county $controls $vra_control c.irca_std##1.p102_full##ib2.x_single [weight = cuts] if cuts==1, a($fe) cluster($cluster)
	estadd scalar clusters = e(N_clust)
	eststo single_dist_dem
	
	//Drop minority-majority counties
	reghdfe d_share_county $controls $vra_control c.irca_std##1.p102_full##ib2.x_mm [weight = cuts] if StateFIPS!=35, a($fe) cluster($cluster)
	estadd scalar clusters = e(N_clust)
	eststo mm_dem
	
	//Falsification
	reghdfe d_share_county $controls97 $vra_control97 c.irca_std##i.p97_full##ib2.x_placebo [weight = cuts] , a($fe) cluster($cluster)
	estadd scalar clusters = e(N_clust)
	eststo placebo_dem
			

								
****************
* Democrat wins the seat
****************
	 //Baseline
	reghdfe dem_rep_county $controls $vra_control c.irca_std##1.p102_full##ib2.x_base [weight = cuts] , a($fe) cluster($cluster)
	estadd scalar clusters = e(N_clust)
	eststo base_seat
	sum dem_rep_county if e(sample) & p102_full==0
	
	 //No controls
	reghdfe dem_rep_county c.irca_std##i.p102_full##ib2.x_none [weight = cuts] , a($fe) cluster($cluster)
	estadd scalar clusters = e(N_clust)
	eststo none_seat
	
	//Extra controls
	reghdfe dem_rep_county $controls $vra_control $extras c.irca_std##i.p102_full##ib2.x_extra [weight = cuts] , a($fe) cluster($cluster)
	estadd scalar clusters = e(N_clust)
	eststo extra_seat
	
	//1980 Controls
	reghdfe dem_rep_county $controls1980 $vra_control c.irca_std##i.p102_full##ib2.x_1980 [weight = cuts] , a($fe) cluster($cluster)	
	estadd scalar clusters = e(N_clust)
	eststo 	eighty_seat
	
	//Interacted Observables (Fully Saturated)
	reghdfe dem_rep_county $controls_full $vra_full c.irca_std##i.p102_full##ib2.legal_control_kaplan1991 [weight = cuts] , a($fe) cluster($cluster)
	estadd scalar clusters = e(N_clust)
	eststo full_seat
	
	//Alternative Definition of Legal Control
	reghdfe dem_rep_county $controls $vra_control c.irca_std##i.p102_full##ib2.x_arp [weight = cuts] , a($fe) cluster($cluster)
	estadd scalar clusters = e(N_clust)
	eststo arp_seat
	
	//Using Hispanic share instead of imputing
	reghdfe dem_rep_county $controls $vra_control c.irca_pc1990_hisp_std##i.p102_full##ib2.x_hisp [weight = cuts] , a($fe) cluster($cluster)
	estadd scalar clusters = e(N_clust)
	eststo hisp_seat
	
	//Drop imputed counties
	reghdfe dem_rep_county $controls $vra_control c.irca_std##i.p102_full##ib2.x_treated if unassigned_county == 0 [weight = cuts], a($fe) cluster($cluster)
	estadd scalar clusters = e(N_clust)
	eststo no_impute_seat
	
	 //Only single district counties
	reghdfe dem_rep_county $controls $vra_control c.irca_std##1.p102_full##ib2.x_single [weight = cuts] if cuts==1, a($fe) cluster($cluster)
	estadd scalar clusters = e(N_clust)
	eststo single_dist_seat
	
	//Drop minority-majority counties
	reghdfe dem_rep_county $controls $vra_control c.irca_std##1.p102_full##ib2.x_mm [weight = cuts] if StateFIPS!=35, a($fe) cluster($cluster)
	estadd scalar clusters = e(N_clust)
	eststo mm_seat
	
	//Falsification
	reghdfe dem_rep_county $controls97 $vra_control97 c.irca_std##i.p97_full##ib2.x_placebo [weight = cuts] , a($fe) cluster($cluster)
	estadd scalar clusters = e(N_clust)
	eststo placebo_seat
	  

**************
* Combine
**************
	//With Headings
	coefplot base none extra eighty full arp hisp no_impute single_dist mm placebo, bylabel("(a) Hispanic Wins Seat") ///
		||  *_dem ,  bylabel("(b) D Vote Share") ///
		||  *_seat ,  bylabel("(c) D Wins Seat") ///
		|| , keep(1.p102_full#1.x_base#c.irca_std ///
			1.p102_full#1.x_none#c.irca_std ///
			1.p102_full#1.x_extra#c.irca_std ///
			1.p102_full#1.x_1980#c.irca_std ///
			1.p102_full#1.legal_control_kaplan1991#c.irca_std ///
			1.p102_full#1.x_arp#c.irca_std ///
			1.p102_full#1.x_hisp#c.irca_pc1990_hisp_std ///
			1.p102_full#1.x_treated#c.irca_std ///
			1.p102_full#1.x_single#c.irca_std ///
			1.p102_full#1.x_mm#c.irca_std ///
			1.p97_full#1.x_placebo#c.irca_std) ///
			xlabel(-0.05(0.05)0.15) xscale(range(-0.05(0.05)0.15)) ///
			coeflabels(1.p102_full#1.x_base#c.irca_std = "Baseline (1)" ///
						1.p102_full#1.x_none#c.irca_std = "No Controls (2)" ///
						1.p102_full#1.x_extra#c.irca_std = "Extra Controls (3)" ///
						1.p102_full#1.x_1980#c.irca_std = "1980 Controls (4)" /// 
						1.p102_full#1.legal_control_kaplan1991#c.irca_std = "Fully Interacted (5)" /// 
						1.p102_full#1.x_arp#c.irca_std = "Legal Control (6)" /// 
						1.p102_full#1.x_hisp#c.irca_pc1990_hisp_std = "Hispanic Imputation (7)" /// 
						1.p102_full#1.x_treated#c.irca_std = "No Imputation (8)" /// 
						1.p102_full#1.x_single#c.irca_std = "Single Districts (9)" ///
						1.p102_full#1.x_mm#c.irca_std = "Drop NM (10)" ///
						1.p97_full#1.x_placebo#c.irca_std = "1980 Placebo (11)") ///
						headings(1.p102_full#1.x_base#c.irca_std = `"{bf:Empirical Specifications}"'        ///
								1.p102_full#1.x_treated#c.irca_std = `"{bf:Sample Restrictions}"'                     ///
							   1.p97_full#1.x_placebo#c.irca_std = `""{bf:Placebo}" ""' ) ///
							   byopts(legend(off) row(1) xrescale) xsize(8) ///
							   xline(0) ciopts(recast(rcap) lcolor(gs8)) msymbol(smcircle) grid(none) offset(1/128)
	
	
	graph export fig9.pdf, replace
	graph save fig9.gph, replace
	
